package com.ruoyi.ies.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ies.domain.VehicleMaintenance;
import com.ruoyi.ies.service.IVehicleMaintenanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆维修Controller
 *
 * @author July
 * @date 2023-06-12
 */
@RestController
@RequestMapping("/ies/maintenance")
public class VehicleMaintenanceController extends BaseController
{
    @Autowired
    private IVehicleMaintenanceService vehicleMaintenanceService;

    /**
     * 查询车辆维修列表
     */
    @PreAuthorize("@ss.hasPermi('ies:maintenance:list')")
    @GetMapping("/list")
    public TableDataInfo list(VehicleMaintenance vehicleMaintenance)
    {
        startPage();
        List<VehicleMaintenance> list = vehicleMaintenanceService.selectVehicleMaintenanceList(vehicleMaintenance);
        return getDataTable(list);
    }

    /**
     * 导出车辆维修列表
     */
    @PreAuthorize("@ss.hasPermi('ies:maintenance:export')")
    @Log(title = "车辆维修", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VehicleMaintenance vehicleMaintenance)
    {
        List<VehicleMaintenance> list = vehicleMaintenanceService.selectVehicleMaintenanceList(vehicleMaintenance);
        ExcelUtil<VehicleMaintenance> util = new ExcelUtil<VehicleMaintenance>(VehicleMaintenance.class);
        util.exportExcel(response, list, "车辆维修数据");
    }

    /**
     * 获取车辆维修详细信息
     */
    @PreAuthorize("@ss.hasPermi('ies:maintenance:query')")
    @GetMapping(value = "/{vehicleId}")
    public AjaxResult getInfo(@PathVariable("vehicleId") Long vehicleId)
    {
        return success(vehicleMaintenanceService.selectVehicleMaintenanceByVehicleId(vehicleId));
    }

    /**
     * 新增车辆维修
     */
    @PreAuthorize("@ss.hasPermi('ies:maintenance:add')")
    @Log(title = "车辆维修", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VehicleMaintenance vehicleMaintenance)
    {
        return toAjax(vehicleMaintenanceService.insertVehicleMaintenance(vehicleMaintenance));
    }

    /**
     * 修改车辆维修
     */
    @PreAuthorize("@ss.hasPermi('ies:maintenance:edit')")
    @Log(title = "车辆维修", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VehicleMaintenance vehicleMaintenance)
    {
        return toAjax(vehicleMaintenanceService.updateVehicleMaintenance(vehicleMaintenance));
    }

    /**
     * 删除车辆维修
     */
    @PreAuthorize("@ss.hasPermi('ies:maintenance:remove')")
    @Log(title = "车辆维修", businessType = BusinessType.DELETE)
    @DeleteMapping("/{vehicleIds}")
    public AjaxResult remove(@PathVariable Long[] vehicleIds)
    {
        return toAjax(vehicleMaintenanceService.deleteVehicleMaintenanceByVehicleIds(vehicleIds));
    }
}
